package com.yonyou.sto.modules.ims.controller;

import com.yonyou.sto.common.api.CommonResult;
import com.yonyou.sto.modules.ims.service.ImsCancleInvoiceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 作废单据管理前端控制器
 * </p>
 *
 * @author barry
 * @since 2022-12-08
 */
@RestController
@RequestMapping("/server/ims/imsCancelInvoice")
@Api(tags = "ImsCancelInvoiceController", description = "作废单据管理")
public class ImsCancelInvoiceController {

    @Autowired
    private ImsCancleInvoiceService imsCancleInvoiceService;

    @ApiOperation("已开票条件分页查询开票数据")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<Map<String, Object>> list(Principal principal,
                                                  @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                  @RequestParam(value = "billSerial", required = false) String billSerial,
                                                  @RequestParam(value = "billSn", required = false) String billSn,
                                                  @RequestParam(value = "billType", required = false) String billType,
                                                  @RequestParam(value = "billNo", required = false) String billNo,
                                                  @RequestParam(value = "billCode", required = false) String billCode,
                                                  @RequestParam(value = "sellerName", required = false) String sellerName,
                                                  @RequestParam(value = "buyerName", required = false) String buyerName,
                                                  @RequestParam(value = "status", required = false) Integer status,
                                                  @RequestParam(value = "startTime", required = false) String startTime,
                                                  @RequestParam(value = "endTime", required = false) String endTime,
                                                  @RequestParam(value = "createName", required = false) String createName,
                                                  @RequestParam(value = "djlx", required = false) String djlx)

    {
        if (principal == null) return CommonResult.unauthorized(null);

        List<Integer> statusList = new ArrayList<>();
        if(status!=null){
            statusList.add(status);
        }else {
            statusList.add(6);
        }
        return imsCancleInvoiceService.list(principal.getName(), pageSize, pageNum,billSerial, billSn,billNo,billCode ,sellerName, buyerName, statusList, startTime, endTime,djlx,billType,createName);
    }

    @ApiOperation("查询单据明细和退回记录")
    @GetMapping(value = "/invoiceInfo")
    public CommonResult invoiceInfo(@RequestParam String id) {
        return imsCancleInvoiceService.invoiceInfo(id);
    }
}
